
	public class BinarySearchTree<T extends Comparable<T>> extends BinaryTree<T> {
	
	BinarySearchTree (TreeNode<T> r){
		super(r);
	}
	BinarySearchTree(){
		super();
	}
	public TreeNode<T> insert(T r) {
		return insert(new TreeNode<T>(r));
	}


	public TreeNode<T> insert(TreeNode<T> r) {
		if (super.getRoot() != null)
			return insert(r, super.getRoot());
		else
			super.setRoot(r);
		return super.getRoot();
	}
		
	public int size(){
		return size(0, super.getRoot());
	}
	
	public int height(){
		return height(-1,super.getRoot());
	}
	public int leaves(){
		return leaves(0,super.getRoot());
	}
	private int leaves(int i, TreeNode<T> r){
		if (r!= null){
			if (r.getLeft()== null && r.getRight() == null)
				i++;
			else
				i= leaves(i,r.getLeft());
				i= leaves(i,r.getRight());
		}
		return i;
	}
	
	private int height(int i, TreeNode<T> r){
		int j=0;
		int k=0;
		if (r != null){
			i++;
			j= height(0, r.getLeft());
			k= height(0, r.getRight());
			i += (k > j) ? k : j;
		}
		return i;
	}
	private int size(int i, TreeNode<T> r){
		if(r!= null){
			i++;
			i = size(i, r.getRight());
			i = size(i, r.getLeft());
		}
		return i;
	}
	
	
	private TreeNode<T> insert (TreeNode<T> key, TreeNode<T> node){
		if(key != null){
			if (key.getKey().compareTo(node.getKey()) < 0)
				if (node.getLeft() == null)
					return node.setLeft(key);
				else
					return insert(key,node.getLeft());
			else
				if (key.getKey().compareTo(node.getKey()) > 0)
					if(node.getRight() == null)
						return node.setRight(key);
					else
						return insert(key,node.getRight());
			
		}
		throw new java.util.NoSuchElementException();  
	}
}
